package main

import (
	"imooc.com/ccmouse/u2pppw/getProxy/redis"
	"strings"
	"log"
	"net/http"
	"net/url"
	"time"
)

func main() {
	testRedisProxy1()
}

func testRedisProxy1() {
	proxys := redis.GetAllProxy(0, -1)
	for i, v := range proxys {
		v = strings.Replace(v, "[", "", 1)
		v = strings.Replace(v, "]", "", 1)
		err := testProxy1(v)
		if err != nil {
			redis.DeleteProxy(proxys[i])
		}
	}
}
func testProxy1(url1 string) error {
	defer func() {
		if r := recover(); r != nil {
			log.Println(r)
		}
	}()
	proxy := func(_ *http.Request) (*url.URL, error) {
		return url.Parse("http://" + url1)
	}
	transport := &http.Transport{Proxy: proxy}
	client := &http.Client{
		Transport: transport,
		Timeout:   time.Second * 10,
	}
	_, err := client.Get("http://www.89ip.cn/tqdl.html?api=1&num=50&port=&address=&isp=") //请求并获取到对象,使用代理

	return err
}
